import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import { useAuthStore } from '@/stores/auth'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import backToTopPlugin from "@/plugins/backToTopPlugin.js";

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)
app.use(ElementPlus)
app.use(backToTopPlugin)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

const authStore = useAuthStore()
authStore.fetchToken()
    .then(() => {
        app.mount('#app')
    })
    .catch((error) => {
        console.error('Failed to initialize app:', error)
        app.mount('#app') // 即使获取token失败也继续挂载应用
    })
